﻿using System.Security.Cryptography;

namespace DoNet.Common.Helpers
{
    public class StringHelper
    {
        /// <summary>
        /// 可以用于生成16/32密钥
        /// </summary>
        /// <param name="length">指定长度，默认32</param>
        /// <returns></returns>
        public static string GenerateSecureToken(int length = 32)
        {
            using var rng = RandomNumberGenerator.Create();
            var tokenData = new byte[length];
            rng.GetBytes(tokenData);
            return Convert.ToBase64String(tokenData);
        }
    }
}
